home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / misc / WHDLoad_dev.lha / WHDLoad / Src / qa / qa.pl < prev    next >
Encoding:
Perl Script  |  2003-12-01  |  4.3 KB  |  176 lines

  1. #!/usr/bin/perl -w
  2. # $Id: qa.pl 1.5 2003/12/01 00:01:02 wepl Exp wepl $
  3.  
  4. $| = 1;    # autoflush
  5. $sourcefile = "qa.asm";
  6. @reasonfiles = ( "Includes:whdload.i","../whd.i" );
  7. $reasonfile = 'tdreason.i';
  8. $whdloadbase = "WHDLoad Slave=QA.Slave NoReq SplashDelay=0";
  9. $tmpfile = "T:qa.tmp";
  10. $logfile = "qualitycheck.log";
  11.  
  12. # arguments
  13. if (@ARGV > 0) {
  14.   foreach (@ARGV) {
  15.     if (/^\d+$/) {
  16.       push @nums,$_;
  17.     } elsif (/^(\d+)\-(\d+)$/ and $1 < $2) {
  18.       $i = $1;
  19.       while ($i <= $2) {
  20.         push @nums,$i++;
  21.       }
  22.     } else {
  23.       die "usage: perl qa.pl [number number-number...]\n";
  24.     }
  25.   }
  26. } else {
  27.   @nums = ();
  28. }
  29.  
  30. # check cpu type
  31. $_ = `cpu`;
  32. /System: 680(\d\d) / or die "cannot parse output from CPU command '$_'";
  33. $cpu = $1;
  34. sub ChkNum {
  35.   $num = shift;
  36.   if (@nums) {
  37.     if (grep(/$num/,@nums)) { return 1 } else { return 0 }
  38.   }
  39.   if ($cpu < 30) {
  40.     if ($num < 30000) { return 1 } else { return 0 }
  41.   } elsif ($cpu == 30) {
  42.     if ($num < 40000) { return 1 } else { return 0 }
  43.   } elsif ($cpu == 40 or $cpu == 60) {
  44.     if ($num < 30000 or $num >= 40000) { return 1 } else { return 0 }
  45.   } else {
  46.     die "unknown cpu type '680$cpu'";
  47.   }
  48. }
  49.  
  50. # collect TDREASON values
  51. if (&Newer($reasonfile,@reasonfiles)) {
  52.   open OUT,">$reasonfile" or die "$reasonfile:$!";
  53.   foreach $file (@reasonfiles) {
  54.     print "parsing '$file'\n";
  55.     open IN,$file or die "$file:$!";
  56.     while (<IN>) {
  57.       if (/^TDREASON_(\w+)\s*=\s*(-?\d+)/) {
  58.         $reason{$1} = $2;
  59.         $rsnnum{$2} = $1;
  60.     print OUT "TDREASON_$1=$2\n";
  61.       }
  62.     }
  63.     close IN;
  64.   }
  65.   close OUT;
  66. } else {
  67.   print "parsing '$reasonfile'\n";
  68.   open IN,$reasonfile or die "$reasonfile:$!";
  69.   while (<IN>) {
  70.     if (/^TDREASON_(\w+)=(-?\d+)/) {
  71.       $reason{$1} = $2;
  72.       $rsnnum{$2} = $1;
  73.     }
  74.   }
  75.   close IN;
  76. }
  77. sub Newer {
  78.   my($base,$basetime,$act,$acttime);            #local variables
  79.   $base = shift;                    #first arg is base file
  80.   if (-f $base) {
  81.     $basetime = (stat($base))[9] || die "$base:$!";    #modification stamp
  82.     while ($act = shift) {
  83.       $acttime = (stat($act))[9] || return 0;        #modification stamp
  84.       if ($acttime > $basetime) {
  85.         return 1;
  86.       }
  87.     }
  88.     return 0;
  89.   } else {
  90.     return 1;
  91.   }
  92. }
  93. print "found " . scalar(keys(%reason)) . " TDREASON's\n";
  94.  
  95.  
  96. open IN,$sourcefile or die "$!:$sourcefile";
  97. while (<IN>) {
  98.   if (/^\s+TAB\s+(\d+),.*;(.*?)\s*;(.*?)[\s\r\n]*$/) {
  99.     $num = $1; &ChkNum($num) or next;
  100.     $rsn = $2;
  101.     $arg = $3;
  102.     ($rsn,@pat) = split ',',$rsn;
  103.     print "$num $arg -> ";
  104.     $rc = system("$whdloadbase Custom1=$num $arg >$tmpfile") / 256;
  105.     if ($rc != 0 and $rc < 100) {
  106.       &ReadFile($tmpfile);
  107.       die "whdload return code = $rc\n$_";
  108.     }
  109.     $out = &ReadFile($tmpfile);
  110.     if ($rc == 0) { $rc = -1 } else { $rc -= 100 }
  111.     if ($rc != $reason{$rsn}) {
  112.       print "FAILED expected $rsn got $rsnnum{$rc}\n";
  113.       $error = "$num using '$arg' expected $rsn got $rsnnum{$rc}\n";
  114.     } else {
  115.       $err = 0;
  116.       foreach (@pat) {
  117.         $pat = $_;
  118.     $pat =~ s/\$/\\\$/g;
  119.         if ($out !~ /$pat/) {
  120.           $err = 1;
  121.           last;
  122.         }
  123.       }
  124.       if ($err) {
  125.         print "FAILED $rsn pattern '$pat' not found in output\n";
  126.         $error = "$num using '$arg' got $rsn pattern '$pat' not found\n";
  127.       } else {
  128.         print join(',',$rsn,@pat) . "\n";
  129.         next;
  130.       }
  131.     }
  132.     print $out;
  133.     push @error,$error;
  134.     &log("$error$out");
  135.   }
  136. }
  137.  
  138. if (@error) {
  139.   print "the following checks had errors:\n";
  140.   foreach (@error) {
  141.     print $_;
  142.   }
  143. } else {
  144.   print "no errors :-)\n";
  145. }
  146.  
  147. sub log {
  148.   open OUT,">>$logfile" or die "$logfile:$!";
  149.   print OUT "----------------- " . &DateStamp . " -----------------\n@_";
  150.   close OUT;
  151. }
  152.  
  153. ###########################################################################
  154. # returns date stamp as string "01.01.1970" from time value
  155. sub DateStamp {
  156.   local(@t) = localtime(time);
  157.   return sprintf("%02d.%02d.%d %02d:%02d:%02d",
  158.     $t[3],$t[4]+1,$t[5]+1900,$t[2],$t[1],$t[0]);
  159. }
  160.  
  161. ###########################################################################
  162. # read complete file into string variable
  163. # 1st parameter = filename
  164. #
  165. sub ReadFile {
  166.   my($name) = shift;
  167.   local(*IN,$size);
  168.   open(IN,$name) or die "$name:$!";
  169.   #binmode IN;            # permit cr/lf transation under M$
  170.   $size = (stat(IN))[7];
  171.   ($size == sysread(IN,$_,$size)) or die "$name:$!";
  172.   close(IN);
  173.   return $_;
  174. }
  175.  
  176.